package com.beyondbit.demo.controller;

import com.beyondbit.demo.entity.Archivetransfer;
import com.beyondbit.demo.entity.User;
import com.beyondbit.demo.entity.query.ArchivetransferQuery;
import com.beyondbit.demo.service.ArchivetransferService;
import com.beyondbit.demo.service.BaseUserServiceException;
import com.beyondbit.web.infrastructure.controller.BaseApiController;

import com.beyondbit.web.infrastructure.entity.Page;
import com.beyondbit.web.infrastructure.model.JsonResultMessage;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 档案归档
 *
 * @author lifangxia
 * @email lifangxia@gmail.com
 * @date 2021-12-01 13:10:36
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/archivetransfer")
public class ArchivetransferController extends BaseApiController {
    @Autowired
    private ArchivetransferService archivetransferService;


    @GetMapping("query")
    public JsonResultMessage<Page<Archivetransfer>> query(ArchivetransferQuery archivetransferQuery) {

        val archivetransferPage = archivetransferService.query(archivetransferQuery);
        return success(archivetransferPage);
    }

    @GetMapping("{id}")
    public JsonResultMessage<Archivetransfer> get(@PathVariable(value = "id") String id) {
        var archivetransfer = archivetransferService.get(id);

        return success(archivetransfer);
    }

    @PostMapping("add")
    public JsonResultMessage add(@RequestBody @Valid Archivetransfer archivetransfer) {
        try {

            archivetransferService.add(archivetransfer);

            return success("新增成功");
        } catch (BaseUserServiceException e) {
            e.printStackTrace();
            return apiErrorResult(e);
        }
    }

    @PostMapping("update/{id}")
    public JsonResultMessage update(@PathVariable(value = "id") String id, @RequestBody Archivetransfer archivetransfer) {

        archivetransfer.setId(id);
        archivetransferService.update(archivetransfer);

        return success("修改成功");
    }

    @PostMapping("delete/{id}")
    public JsonResultMessage delete(@PathVariable(value = "id") String id) {
        archivetransferService.delete(id);

        return success("删除成功");
    }

    @GetMapping("/type/{type}")
    public JsonResultMessage queryDicTypeList(@PathVariable(value = "type") String type) {
        var typeList = archivetransferService.queryDicTypeList(type);
        return success("查询成功！@", typeList);
    }
}
